package com.soft.base.contract;

/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class Cache {

    private Cache() {
    }

    private static CacheFacade cacheFacade;

    public static synchronized void boot(CacheFacade cacheFacade) {
        Cache.cacheFacade = cacheFacade;
    }

    /**
     * forget
     * @param key
     */
    public static void forget(String key) {
        cacheFacade.forget(key);
    }

    /**
     * exists
     * @param key
     * @return
     */
    public static boolean exists(String key) {
        return cacheFacade.exists(key);
    }

    /**
     * getObject
     * @param key
     * @param cls
     * @param <T>
     * @return
     */
    public static <T> T getObject(String key, Class<T> cls) {
        return cacheFacade.getObject(key, cls);
    }

    /**
     * setObject
     * @param key
     * @param data
     * @param <T>
     */
    public static <T> void setObject(String key, T data) {
        cacheFacade.setObject(key, data);
    }

    /**
     * setObject
     * @param key
     * @param data
     * @param expire
     * @param <T>
     */
    public static <T> void setObject(String key, T data, long expire) {
        cacheFacade.setObject(key, data, expire);
    }

    /**
     * remember
     * @param key
     * @param seconds
     * @param callback
     * @param <T>
     * @return
     */
    public static <T> T remember(String key, long seconds, CacheFacade.RememberCallback<T> callback) {
        return cacheFacade.remember(key, seconds, callback);
    }
}
